package cn.itsource.hbc.quartz.service.impl;

import cn.itsource.hbc.quartz.domain.QuartzJobInfo;
import cn.itsource.hbc.quartz.job.MainJob;
import cn.itsource.hbc.quartz.service.IQuartzService;
import cn.itsource.hbc.quartz.utils.QuartzUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.stereotype.Service;

@Service
public class QuartzServiceImpl implements IQuartzService {

    @Autowired
    private SchedulerFactoryBean factoryBean;


    @Override
    public void addJob(QuartzJobInfo quartzJobInfo) {
          /*
        Scheduler：调度器
        jobName：任务名称
        cls：cls用来定义自己的业务逻辑的类  实现Job接口
        params：携带的参数
        time：触发器的时间表达式

        */

        QuartzUtils.addJob(factoryBean.getScheduler(),quartzJobInfo.getJobName(), MainJob.class,quartzJobInfo.getParams(),quartzJobInfo.getCronj());


    }

    @Override
    public void removeJob(String jobName) {
        QuartzUtils.removeJob(factoryBean.getScheduler(),jobName);
    }
}
